package com.metasoft.flex.dto {
	
	import com.metasoft.flex.dto.XMLInfo;
	import com.metasoft.flex.dto.UsageEnvironment;
	import com.metasoft.flex.dto.UserInfo;
	import com.metasoft.flex.dto.UsageHistory;
	import com.metasoft.flex.dto.ClassificationPref;
	import com.metasoft.flex.dto.CreationPref;
	
	public class UploadPersonalInfo 
	implements XMLInfo {
		
		public var creationPref:CreationPref;
		public var classificationPref:ClassificationPref;
		public var usagHistory:UsageHistory;
		public var userInfo:UserInfo;
		public var usageEnv:UsageEnvironment;
		

		public var UpoadInfo_Header:String = "<upload_Personal_Data xmlns=\"urn:tva:transport:2005\" " + 
				"xmlns:urn=\"urn:tva:metadata:2005\" " + 
				"xmlns:urn1=\"urn:tva:mpeg7:2005\" " + 
				"xmlns:urn2=\"urn:tva:metadata:extended:2005\" " + 
				"xmlns:urn3=\"urn:tva:mpeg21:2005\">";
				
		public function set creationPreferece(creationPref:CreationPref):void {
			this.creationPref = new CreationPref();
			this.creationPref = creationPref;
		}
		
		public function set classificationPreference(classificationPref:ClassificationPref):void {
			this.classificationPref = new ClassificationPref();
			this.classificationPref = classificationPref;
		}
		
		public function set usageHistory(usageHistory:UsageHistory):void {
			this.usagHistory = new UsageHistory();
			this.usagHistory = usageHistory;
		}
		
		public function set UserInformation(userInfo:UserInfo):void {
			this.userInfo = new UserInfo();
			this.userInfo = userInfo;
		}
		
		/**
		 * Converts this object to XML String.
		 */		
		public function toXMLString():String {
			
			var upInfo:String = new String();
			
			upInfo = upInfo.concat(UpoadInfo_Header);
			
			// for User Preference Table
			if (creationPref != null || classificationPref != null) {
				upInfo = upInfo.concat("<urn:UserPreferences>");
				upInfo = upInfo.concat("<urn1:FilteringAndSearchPreferences>");
				
				if (creationPref != null) { 
					upInfo = upInfo.concat(creationPref.toXMLString());
		    	}
			    
				if (classificationPref != null) {
					upInfo = upInfo.concat(classificationPref.toXMLString());
				}
				upInfo = upInfo.concat("</urn1:FilteringAndSearchPreferences>");				
				upInfo = upInfo.concat("</urn:UserPreferences>");
			}
			
			// For Usage History
			if (usagHistory != null) {
				upInfo = upInfo.concat(usagHistory.toXMLString());	
			}
			
			// For UserInformation Table
			if (userInfo != null) {
				upInfo = upInfo.concat(userInfo.toXMLString());
			}
			
			// For UsageEnvironment
			if (usageEnv != null) {
				upInfo = upInfo.concat(usageEnv.toXMLString());
			}
			
			upInfo = upInfo.concat("</upload_Personal_Data>");
			
			return upInfo;
		}
	}
}